Ext.define('HelloWorld.controller.Main', {
	extend: 'Ext.app.Controller',
	config:{
		before:{
			'loginById': ['checkId', 'ensureLoaded']
		},
		control: {
			loginButton: {
				//tap: 'doLogin'
			},
			'button[action=logout]': {
				tap: 'doLogout'
			},
			increased: {
				tap: 'increased'
			},
			decreased: {
				tap: 'decreased'
			}
		},
		routes: {
			'login/:id': 'loginById',
			'showName/:name': {
				action: 'showName',
				conditions: {
					':name': '[0-9a-zA-Z\.]+'
				}
			}
		},
		refs:{
			nav: '#mainNav',
			loginButton: '#mybutton',
			increased: '#increased',
			decreased: '#decreased'
		}
	},
	showName: function(name){
		console.log("Your name is: "+name);
	},
	increased: function(){
		console.log("increased");
		var view = Ext.Viewport.getActiveItem();
		var value = view.getBorder()+1;
		console.log(value);
		view.setBorder(value);
		console.log(view.getBorder());
	},
	decreased: function(){
		console.log("decreased");
		var view = Ext.Viewport.getActiveItem();
		console.log(view.getBorder());
		var value = view.getBorder()-1;
		var tempvalue = (value <= 0)?0:value;
		console.log(tempvalue);
		view.setBorder(tempvalue);
	},
	checkId: function(action){
		if(true){
			action.resume();
		}else{
			console.log("Less than 1");
		}
	},
	addLoginButton: function(){
		this.getNav().add({
			text: 'Login'
		});
	},
	doLogin: function(){
		console.log("Login");
	},
	doLogout: function(){
		console.log("Logout");
	},
	launch: function(){
		this.callParent();
		console.log("launch controller");
	},
	init: function(){
		this.callParent();
		console.log("init controller");
	},
	loginById: function(id){	
		console.log(id);
	},
	ensureLoaded: function(action){
		Ext.require(["HelloWorld.model.Customer"], function(){
			action.resume();
		});
	}
});

Ext.create('Ext.Toolbar', {
	id:'mainNav',
	items: [
		{
			text: 'some text'
		}
	]
});